<?php
session_start();
$connect = mysql_connect("localhost", "root", "") or die ("Error , check your server connection.");
mysql_select_db("stms");
 
$Regno=$_POST['Regno'];
$Level=$_POST['Level'];
$Course1=$_POST['Course1'];
$Course2=$_POST['Course2'];
$Course3=$_POST['Course3'];
$Course4=$_POST['Course4'];
$Course5=$_POST['Course5'];
$Course6=$_POST['Course6'];

$course=$_POST['course'];
$result=mysql_query("SELECT * FROM combination WHERE Regno='$Regno' and Level='$Level'");
 $insert="Add";
 $update="Update";
 $delete="Delete";
 
 if($_POST['Add']==$insert)
 {

 if (mysql_num_rows($result) == 1){
 	  	 //header("Location:http://localhost/stms/pages/compinadmin.php?err=The Regno and Level  is already exist");

$_SESSION['error']="This Regno is already exist";
 }
 else
 {
if ($Regno=="" or $Level==""){
		  	 //header("Location:http://localhost/stms/pages/compinadmin.php?err=REGNO AND level must be entered, hit back button and re-enter information");
$_SESSION['add']="REGNO AND level must be entered, hit back button and re-enter information";
	}
	else{
	$query="insert into combination values('$Regno','$Level','$Course1','$Course2','$Course3','$Course4','$Course5','$Course6')";
	mysql_query($query)  or die(mysql_error());
		  	 //header("Location:./../attendadmin.php");
$_SESSION['add']="Your message has been received";
$_SESSION['delete'] = "";
	
}
}
}
else if($_POST['Update']==$update)
{
if (mysql_num_rows($result))
{
	$upd="UPDATE combination SET Course1='$Course1',Level='$Level',Course2='$Course2',Course3='$Course3',Course4='$Course4',Course5='$Course5',Course6='$Course6' WHERE Regno='$Regno' and Level='$Level'";

	mysql_query($upd)  or die(mysql_error());
		  	 //header("Location:http://localhost/stms/pages/compinadmin.php?err=Updated successfully");
$_SESSION['update']="Updated successfully";
	
 }
 
 else 
 	  	 //header("Location:http://localhost/stms/pages/compinadmin.php?err=There is no Regno as you given");
$_SESSION['update']= "There is no Regno as you given";

 }
 else if($_POST['Delete']==$delete)
 {
 
if (mysql_num_rows($result)==1)
 {
 $del="DELETE FROM combination WHERE Regno ='$Regno' AND Level='$Level'";
 mysql_query($del) ; 
 //or die($_SESSION['delete']="aa");
 	  	// header("Location:http://localhost/stms/pages/compinadmin.php?err=Deleted successfully");
		
		$_SESSION['delete'] = "Deleted successfully";
		$_SESSION['add']="";
	

	}
	else{
		$_SESSION['delete']="Regno is not there";
	}
		  	//header("Location:http://localhost/stms/pages/compinadmin.php?err=Regno is not there");

	
	
 
 }
 if(isset($_POST['Search']))
 {
	header("Location:http://localhost/stms/pages/compinadmin.php?err1=$Regno.$Level");
 }
 
 if(isset($_POST['Search2']))
 {
 
  $se=$_POST['Searcher'];
   $_SESSION['error']=  $se;
  
	//header("Location:http://localhost/stms/pages/compinadmin.php?err2=$se");
	
	
 }
 
?>